package com.meilai.project.controller.app;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.middleware.CaptchaDTO;
import com.meilai.project.service.middleware.CaptchaService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张驰
 * @date 2020/12/3 17:02
 */
@Api(value = "图片验证码控制器", description = "图片验证码相关")
@RestController
@RequestMapping("api/app/captcha")
public class CaptchaController {
    private final static Logger logger = LoggerFactory.getLogger(CaptchaController.class);

    @Autowired
    private CaptchaService service;

    /**
     * 获取图片验证码接口
     */
    @PostMapping(value = "/image")
    public String imageCode() {
        return service.getCodeImage(110,40);
    }

    /**
     * 检查会话验证码信息是否正确，正确则发送短信验证码
     */
    @PostMapping(value = "/image/check_send_sms")
    public CommonResult checkCodeAndSendSMSCode(@RequestBody CaptchaDTO dto){
        return service.checkCodeAndSendSMSCode(dto);
    }

    /**
     * 发送短信验证码
     */
    @PostMapping(value = "/send_sms")
    public CommonResult sendSMSCode(@RequestBody CaptchaDTO dto){
        return service.sendSMSCode(dto);
    }
}
